package com.geekhome.player.domain.service;

import com.geekhome.player.domain.dao.PlayerRepository;
import com.geekhome.player.domain.entity.PlayerBaseDO;
import com.geekhome.player.global.common.SysConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * Copyright © 2018年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * 用户相关服务类
 * @Date 2018/8/30 20:47
 */
@Service
public class PlayerServices {

    @Autowired
    private PlayerRepository playerRepository;

    /**
     * 查询所有的用户信息
     * @return
     */
    public List<PlayerBaseDO> getPlayers(){

        return playerRepository.findAll();
    }

    /**
     * 添加一名用户
     * @param userDO
     * @return
     */
    public PlayerBaseDO addPlayer(PlayerBaseDO userDO){

        //注册时间
        userDO.setGmtCreate(LocalDateTime.now());
        //默认角色
        List<String> rolelist = new ArrayList<>();
        rolelist.add(SysConst.ROLE_USER);
        userDO.setRoles(rolelist);

        return playerRepository.save(userDO);
    }

}
